__author__ = 'Denis Zorinets'

from Net import Net
def Exec_ER(size_beg,size_end,size_step,p_beg,p_end,p_step,sigma_steps):
    for size in range(size_beg,size_end,size_step):

        p = p_beg
        while p < p_end:

            SAxis = "X = [ "
            NAxis = "Y = [ "

            N = Net(size)
            N.CalcAll_ER(p)

            sigma_beg = N.FindMinS()
            sigma_end = N.FindMaxS()
            sigma_step = (sigma_end - sigma_beg)/sigma_steps
            sigma = sigma_beg

            while sigma<sigma_end:
                SAxis+=sigma.__str__()+","
                NAxis+=N.FindHidden(sigma).__str__()+","
                sigma+=sigma_step

            SAxis = SAxis[:SAxis.__len__()-1]+"]"
            NAxis = NAxis[:NAxis.__len__()-1]+"]"

            file = open(".//OUT//ER Size= "+size.__str__()+" P= "+p.__str__()+".sce","w+")
            file.write(SAxis+"\r\n"+NAxis+"\r\n"+"plot2d(X,Y)\r\n")
            file.close()

            p+=p_step

def Exec_SW_Mk1(size_beg,size_end,size_step,p_beg,p_end,p_step,rank_beg,rank_end,rank_step,sigma_steps):
    for rank in range(rank_beg,rank_end,rank_step):
        for size in range(size_beg,size_end,size_step):

            p = p_beg
            while p < p_end:

                SAxis = "X = [ "
                NAxis = "Y = [ "

                N = Net(size)
                N.CalcAll_SW_Mk1(p,rank)

                sigma_beg = N.FindMinS()
                sigma_end = N.FindMaxS()
                sigma_step = (sigma_end - sigma_beg)/sigma_steps
                sigma = sigma_beg

                while sigma<sigma_end:
                    SAxis+=sigma.__str__()+","
                    NAxis+=N.FindHidden(sigma).__str__()+","
                    sigma+=sigma_step

                SAxis = SAxis[:SAxis.__len__()-1]+"]"
                NAxis = NAxis[:NAxis.__len__()-1]+"]"

                file = open(".//OUT//SWMk1 Rank ="+rank.__str__()+" Size= "+size.__str__()+" P= "+p.__str__()+".sce","w+")
                file.write(SAxis+"\r\n"+NAxis+"\r\n"+"plot2d(X,Y)\r\n")
                file.close()

                p+=p_step

def Exec_SW_Mk2(size_beg,size_end,size_step,p_beg,p_end,p_step,rank_beg,rank_end,rank_step,sigma_steps):
    for rank in range(rank_beg,rank_end,rank_step):
        for size in range(size_beg,size_end,size_step):

            p = p_beg
            while p < p_end:

                SAxis = "X = [ "
                NAxis = "Y = [ "

                N = Net(size)
                N.CalcAll_SW_Mk2(p,rank)
                sigma_beg = N.FindMinS()
                sigma_end = N.FindMaxS()
                sigma_step = (sigma_end - sigma_beg)/sigma_steps
                sigma = sigma_beg

                while sigma<sigma_end:
                    SAxis+=sigma.__str__()+","
                    NAxis+=N.FindHidden(sigma).__str__()+","
                    sigma+=sigma_step

                SAxis = SAxis[:SAxis.__len__()-1]+"]"
                NAxis = NAxis[:NAxis.__len__()-1]+"]"

                file = open(".//OUT//SWMk2 Rank ="+rank.__str__()+" Size= "+size.__str__()+" P= "+p.__str__()+".sce","w+")
                file.write(SAxis+"\r\n"+NAxis+"\r\n"+"plot2d(X,Y)\r\n")
                file.close()

                p+=p_step


def Exec_SF(size_beg,size_end,size_step,m0_beg,m0_end,m0_step,sigma_steps):
    for m0 in range(m0_beg,m0_end,m0_step):
        for m in range(1,m0+1):
            for size in range(size_beg,size_end,size_step):

                SAxis = "X = [ "
                NAxis = "Y = [ "

                N = Net(size)
                N.CalcAll_SF(m,m0)
                sigma_beg = N.FindMinS()
                sigma_end = N.FindMaxS()
                sigma_step = (sigma_end - sigma_beg)/sigma_steps
                sigma = sigma_beg

                while sigma<sigma_end:
                    SAxis+=sigma.__str__()+","
                    NAxis+=N.FindHidden(sigma).__str__()+","
                    sigma+=sigma_step

                SAxis = SAxis[:SAxis.__len__()-1]+"]"
                NAxis = NAxis[:NAxis.__len__()-1]+"]"

                file = open(".//OUT//SF M0 = "+m0.__str__()+" M = "+m.__str__()+" Size= "+size.__str__()+".sce","w+")
                file.write(SAxis+"\n"+NAxis+"\n"+"plot2d(X,Y)\n")
                file.close()

#Exec_ER(10,500,10,0.1,0.9,0.1,200)
#Exec_SW_Mk2(10,500,10,0.1,0.9,0.1,1,9,1,200)
#Exec_SW_Mk2(10,500,10,0.1,0.9,0.1,1,9,1,200)
#Exec_SF(10,500,10,2,4,1,200)
